package com.example.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 1. @ClassDescription: 消息队列，Direct类型交换机
 * 2. @author: Z
 * 3. @date: 2023年12月18日 14:25
 */
@Configuration
@Slf4j
public class DirectConfig {

    //声明direct类型交换机
    @Bean
    public DirectExchange directExchange(){
        log.info("交换机baking.direct创建成功");
        return ExchangeBuilder.directExchange("baking.direct").build();
    }

    //声明一个队列
    @Bean
    public Queue directQueue(){
        log.info("队列baking.queue创建成功");
        return new Queue("baking.queue");
    }


    //绑定队列和交换机
    @Bean
    public Binding binding(){
        log.info("交换机和队列绑定成功");
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("order");
    }
}
